package example.utils;

import lombok.Data;

@Data
public class ResultData<T> {

    private static int SUCCESS = 200;
    private static int ERROR = 500;
    private int code;
    private T data;
    private String message;

    public ResultData(int code, T data) {
        this.code = code;
        this.data = data;
    }

    public ResultData(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResultData(int code, String message, T data) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    //成功直接返回
    public static ResultData ok() {
        return new ResultData(SUCCESS, "操作成功!");
    }

    //成功直接返回
    public static ResultData ok(Object data) {
        return new ResultData(SUCCESS, data);
    }

    //失败直接返回 ResultData.fail(msg)
    public static ResultData fail(String msg) {
        return new ResultData(ERROR, msg);
    }

    //失败直接返回 ResultData.fail(msg)
    public static ResultData fail(String msg, Object data) {
        return new ResultData(ERROR, msg, data);
    }
}
